import pubsub, { AXIOS_RESPONSE_ERROR } from '@/utils/pubsub';
import { message } from 'antd';
import { useNavigate } from 'react-router-dom';

export default () => {
	pubsub.on(AXIOS_RESPONSE_ERROR, (error: any) => {
		const { resp_code, msg } = error;
		const [messageApi] = message.useMessage();
		msg && messageApi.error(msg);
		const navigate = useNavigate();
		if (resp_code === 401) {
			// 401 token expired 登陆
			navigate('/login');
		}
	});
};
